package main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import env.City;
import env.Road;
import env.World;

public class Main
{
	// constants
	public static final int noOpCost = 1, hellBreakLooseCost = 100000000, cutoff = 10,
			goalScore = 100;
	public static final double pArmy = 0.4, pChem = 0.3, pReveal = 0.8, pChemCause = 0.9,
			pArmyCause = 0.7;

	public static void main(String[] args)
	{
		World world = utils.Parser.parseWorldFile("world.txt");
		world.initBn();
//		System.out.print(world.output());
		world.resetEvidence();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		boolean quit = false;

		try
		{
			while (!quit)
			{
				System.out
						.println("Choose action:\n\t1)Reset evidence\n\t2)Add evidence\n\t3)Do reasoning\n\t4)Quit");
				line = br.readLine();
				switch (line.charAt(0))
				{
				case '1':
					world.resetEvidence();
					break;
				case '2':
					parseEvidence(world);
					break;
				case '3':
					world.doReasoning();
					break;
				case '4':
					quit = true;
					break;
				default:
					continue;
				} 
			}
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static void parseEvidence(World world)
	{
		System.out.println("Evidence type?:\n\t1)Report\n\t2)Chems\n\t3)army\n\t4)Terrorist");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		City city;
		try
		{
			line = br.readLine();
			switch (line.charAt(0))
			{
			case '1':
				System.out.println("which city?");
				line = br.readLine();
				city = world.getCityByName(line);
				System.out.println("Chems present?([Y]/N)");
				line = br.readLine();
				if (line.equals("n") || line.equals("N"))
					city.setChemsReported(0);
				else
				{
					city.setChemsReported(1);
					city.setChems(1);
				}
					
				break;
			case '2':
				System.out.println("which city?");
				line = br.readLine();
				city = world.getCityByName(line);
				System.out.println("Chems present?([Y]/N)");
				line = br.readLine();
				if (line.equals("n") || line.equals("N"))
				{
					city.setChems(0);
					city.setChemsReported(0);
				}
				else
					city.setChems(1);
				break;
			case '3':
				System.out.println("which city?");
				line = br.readLine();
				city = world.getCityByName(line);
				System.out.println("Army present?([Y]/N)");
				line = br.readLine();
				if (line.equals("n") || line.equals("N"))
					city.setEscorts(0);
				else
					city.setEscorts(1);
				break;

			case '4':
				System.out.println("Road from which city?");
				line = br.readLine();
				city = world.getCityByName(line);
				System.out.println("Road to which city?");
				line = br.readLine();
				Road road = world.getRoadBetweenCities(city, world.getCityByName(line));
				System.out.println("Terrorist present?([Y]/N)");
				line = br.readLine();
				if (line.equals("n") || line.equals("N"))
					road.setEvBlocked(0);
				else
					road.setEvBlocked(1);
				break;
			}
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
/*
 * p_report|pchem = p_reveal = 0.8 = (p(report and chem))/pchem
 * 
 * VERTEX 1: chem reported | chem // P(chem reported | chem) = 0.8 // P(not chem
 * reported | chem) = 0.2 // // P(chem reported | not chem) = 0 // P(not chem
 * reported | not chem) = 1
 */